package com.wenhao.iqiyi;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author Wenhao Tong
 * @create 2021-08-22 15:45
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String next = scanner.next();
        int n = next.charAt(next.length() - 1) - '0';
        int[] path = new int[n];
        for (int i = 0;i < n;i++) {
            path[i] = -1;
        }
        visited = new int[n];
        row = n;
        reverse(0,path);
        System.out.println(result);
//        System.out.println(checkPath(3, new int[]{0,2,4, -1, -1}));
    }

    private static List<List<String>> result = new ArrayList<>();
    private static int[] visited;
    private static int row;

    private static void reverse (int n,int[] path) {
        if (n == row) {
            result.add(getString(path));
            return;
        }
        for (int i = 0;i < row;i++) {
            path[n] = i;
            if (visited[i] == 0 && checkPath(n,path)) {
                visited[i] = 1;
                reverse(n + 1,path);
                visited[i] = 0;
            }
            path[n] = -1;
        }
    }

    private static boolean checkPath(int n,int[] path) {
        for (int i = 0;i <= n;i++) {
            for (int j = i + 1;j <= n;j++) {
                if (Math.abs(i - j) == Math.abs(path[i] - path[j])) {
                    return false;
                }
            }
        }
        return true;
    }

    private static ArrayList<String> getString(int[] path) {
        ArrayList<String> strings = new ArrayList<>();
        for (int i = 0;i < path.length;i++) {
            String s = "";
            for (int j = 0;j < row;j++) {
                if (j == path[i]) {
                    s += "Q";
                } else {
                    s += ".";
                }
            }
            strings.add(s);
        }
        return strings;
    }
}
